<?php

namespace Plugins\IMApi\Listener;

use App\Util\TerminalOutput;
use Hyperf\Event\Annotation\Listener;
use Hyperf\Framework\Event\AfterWorkerStart;

#[Listener]
class UseInfoListener implements \Hyperf\Event\Contract\ListenerInterface
{

    /**
     * @return string[] returns the events that you want to listen
     */
    public function listen(): array
    {
        return [
            AfterWorkerStart::class
        ];
    }

    /**
     * Handle the Event when the event is triggered, all listeners will
     * complete before the event is returned to the EventDispatcher.
     */
    public function process(object $event): void
    {
        TerminalOutput::purple('=================================== WebSocket Server ====================================');
        TerminalOutput::info("== 认证方式为url地址token字段携带jwt信息，例：  ws://127.0.0.1:9502?token=121111");
        TerminalOutput::info("== 认证信息默认识别 user_id 字段， 如有调整请自行修改 WebSocketController::onOpen 的代码");
        TerminalOutput::info("== 修改 dependencies.php 中的配置为自定义消息处理逻辑");
        TerminalOutput::info("== 心跳监听消息为: ping ");
        TerminalOutput::info("== 默认消息处理说明：");
        TerminalOutput::info("== 消息内容为：s(user=1) hello 时，发送给用户ID为1的消息为：hello");
        TerminalOutput::info("== 消息内容为：s(fd=1) hello 时，发送给fd为1的消息为：hello");
        TerminalOutput::info("== 消息内容为：s(room=1) hello 时，发送给房间为1的消息为：hello");
        TerminalOutput::info("== 消息内容为：h(room=1&user=1) 时，用户ID1加入房间ID1");
        TerminalOutput::info("== 消息内容为：h(room=1^user=1) 时，用户ID1退出房间ID1");
        TerminalOutput::info(<<<EOF
        /** http 服务发送消息示例 */
        /** @var ContainerInterface \$container */
        
        \$server = \$container->get(ServerFactory::class)->getServer()->getServer();
        \$this->bindService = \$container->get(BindService::class);
        \$this->senderService = new SenderService(\$server, \$this->bindService);
        \$this->senderService->sendToUserId('1', 'hello world');
        EOF
        );
        TerminalOutput::purple('=========================================================================================');
    }
}